/**   
* @Title: YwShenQingZxView.java 
* @Package com.zjdiepu.www.manage.api.zpp.view 
* 
* @author zhangpp
* @date 2017年5月26日 下午4:41:22 
* @version V1.0   
*/
package com.zjdiepu.www.manage.api.zpp.view;

import io.swagger.annotations.Api;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.type.AttachmentType;
import com.zjdiepu.www.base.enums.type.CreditPeopleType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.util.UUIDFactory;
import com.zjdiepu.www.commpent.ViewScopeControllerHelper;
import com.zjdiepu.www.dao.base.DpBaseDataDictionaryMapper;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.dao.zx.ZxCreditQueryMapper;
import com.zjdiepu.www.ibiz.base.IOtherAttachmentsService;
import com.zjdiepu.www.ibiz.file.IQiniuFileService;
import com.zjdiepu.www.ibiz.zpp.PublicService;
import com.zjdiepu.www.ibiz.zpp.YwShenQingZxService;
import com.zjdiepu.www.ibiz.zx.IZxCreditQueryService;
import com.zjdiepu.www.ibiz.zx.IZxQueryCreditApplySubService;
import com.zjdiepu.www.model.base.dto.OtherAttachments;
import com.zjdiepu.www.model.zx.dto.ZxCreditQuery;
import com.zjdiepu.www.model.zx.dto.ZxQueryCreditApplySub;

/**      
 * 项目名称：diepu-parent-manage   
 * 类名称：YwShenQingZxView   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月26日 下午4:41:22   
 * 修改人：zhangpp
 * 修改时间：2017年5月26日 下午4:41:22   
 * 修改备注：   
 * @version V1.0     
 */
@Controller
@RequestMapping(value= "YwShenQingZxView", produces="application/json;charset=UTF-8")
@Api(tags = {"作者：张鹏鹏，电话：15158822934"}, produces="application/json;charset=UTF-8")
public class YwShenQingZxView extends BaseController
{

	@Resource
    private ViewScopeControllerHelper viewScopeControllerHelper;
	
	@Resource
	private YwShenQingZxService ywShenQingZxService;
	
	@Resource
	private IZxCreditQueryService zxCreditQueryService;
	
	@Resource
	private ZxCreditQueryMapper zxCreditQueryMapper;
	
	@Resource
	private IZxQueryCreditApplySubService zxQueryCreditApplySubService;
	
	@Resource
	private PublicService publicService;
	
	@Resource
	private DpBaseDataDictionaryMapper dpBaseDataDictionaryMapper;
	
	@Resource
	private IOtherAttachmentsService otherAttachmentsService;
	
	@Resource
	private IQiniuFileService iQiniuFileService;
	
	@Resource
	private PublicDao publicDao;
	
	
	/**
	 * 接口征信查询
	 * 征信信息修改
	 * @param model
	 * @param id
	 * @param tid
	 * @param hid
	 * @param creditPeopleType
	 * @return
	 */
	@RequestMapping(value = "autozxQueryCreditApplyUpdate", method = RequestMethod.GET)
    public String autozxQueryCreditApplyUpdate(Model model,String id,String tid,String hid,String creditPeopleType) 
    {
		ZxQueryCreditApplySub zxQueryCreditApplySub = new ZxQueryCreditApplySub();
		zxQueryCreditApplySub.setDpStatus(DpStatus.NORMAL.getCode());
		zxQueryCreditApplySub.setCreditPeopleType(CreditPeopleType.ZHU_JIE_REN.getCode());
		zxQueryCreditApplySub.setQueryCreditApplyId(id);
		zxQueryCreditApplySub = zxQueryCreditApplySubService.selectRefined(zxQueryCreditApplySub);
		if(null != zxQueryCreditApplySub) {
			model.addAttribute("uuid0", zxQueryCreditApplySub.getId());
		}
		//判断条件
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
		model.addAttribute("uuid", id);
		model.addAttribute("tid", tid);
		model.addAttribute("hid", hid);
		model.addAttribute("creditPeopleType",creditPeopleType);
		model.addAttribute("uuid1", tid);
		model.addAttribute("uuid2", tid);
		model.addAttribute("uuid3", tid);
		model.addAttribute("uuid4", tid);
		model.addAttribute("uuid5", tid);
    	return "ywShouLi/ywShenQingAuto/autozxQueryCreditApplyUpdate";
    }
	 
	/**
	 * 接口征信查询
	 * 申请查征信
	 * @param model
	 * @return
	 */
    @RequestMapping(value = "autozxQueryCreditApplyAdd", method = RequestMethod.GET)
    public String autozxQueryCreditApplyAdd(Model model) 
    {
		//判断条件
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
    	//征信主表主键
    	model.addAttribute("uuid", UUIDFactory.getUUID());
		//sub 主借人主键
		model.addAttribute("uuid0", UUIDFactory.getUUID());
		//sub 配偶主键
		model.addAttribute("uuid1", UUIDFactory.getUUID());
		//sub 担保人1主键
		model.addAttribute("uuid2", UUIDFactory.getUUID());
		//sub 担保人2主键
		model.addAttribute("uuid3", UUIDFactory.getUUID());
		//sub 担保人3主键
		model.addAttribute("uuid4", UUIDFactory.getUUID());
		//sub 担保人4主键
		model.addAttribute("uuid5", UUIDFactory.getUUID());
		//sub 担保人5主键
		model.addAttribute("uuid5", UUIDFactory.getUUID());
		//业务申请
		
		//获取银行
		String sqlXmls = "select t.id,t.`value`,t.`name` from dp_base_data_dictionary t where t.parent_value = 'LoanBank' and t.`value` = 'ICBC' and t.dp_status = 1 and t.dp_status = 1";
		Map<String, String> result = publicService.selectMapsSql(sqlXmls);
		model.addAttribute("result", result);
    	return "ywShouLi/ywShenQingAuto/autozxQueryCreditApplyAdd";
    }
    
    /**
     * 接口查征信添加配偶
     * @param model
     * @param creditPeopleType
     * @param id
     * @param tid
     * @param hid
     * @return
     */
	@RequestMapping(value = "autoCreditApplyAddList", method = RequestMethod.GET)
	public String autoCreditApplyAdd(Model model,String creditPeopleType,String id,String tid,String hid) {
	 	
		//判断条件
	 	viewScopeControllerHelper.preparedAttachmentEnum(model);
		model.addAttribute("uuid", UUIDFactory.getUUID());
		model.addAttribute("uuid1", UUIDFactory.getUUID());
		model.addAttribute("uuid2", UUIDFactory.getUUID());
		model.addAttribute("uuid3", UUIDFactory.getUUID());
		model.addAttribute("uuid4", UUIDFactory.getUUID());
		model.addAttribute("uuid5", UUIDFactory.getUUID());
		
		//页面传过的值
		model.addAttribute("creditPeopleType", creditPeopleType);
		model.addAttribute("id", id);
		model.addAttribute("tid", tid);
		model.addAttribute("hid", hid);
		
		//修复添加担保人/配偶图片不依附记录的问题
		otherAttachmentsService.deleteInvalidAttachments(id, getCurrentUser());
		
		//删除附件表
		return "ywShouLi/ywShenQingAuto/autozxCreditApplyAdd";
	}
	
	
	 /**
    * 业务受理 业务申请
    * @author zhangpp
    * @Title: zxQueryCreditApplyAdd 
    * 
    * @param @param model
    * @param @return    设定文件 
    * @return String    返回类型 
    * @version V1.0
    * @throws
     */
    @RequestMapping(value = "zxQueryCreditApplyAdd", method = RequestMethod.GET)
    public String zxQueryCreditApplyAdd(Model model) {
    	
		//判断条件
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
    	
    	//征信主表主键
		model.addAttribute("uuid", UUIDFactory.getUUID());
		//sub 主借人主键
		model.addAttribute("uuid0", UUIDFactory.getUUID());
		//sub 配偶主键
		model.addAttribute("uuid1", UUIDFactory.getUUID());
		//sub 担保人1主键
		model.addAttribute("uuid2", UUIDFactory.getUUID());
		//sub 担保人2主键
		model.addAttribute("uuid3", UUIDFactory.getUUID());
		//sub 担保人3主键
		model.addAttribute("uuid4", UUIDFactory.getUUID());
		//sub 担保人4主键
		model.addAttribute("uuid5", UUIDFactory.getUUID());
		//sub 担保人5主键
		model.addAttribute("uuid5", UUIDFactory.getUUID());
		
		//业务申请
    	return "ywShouLi/ywShenQing/zxQueryCreditApplyAdd";
    }
    
    
	/**
	* 增加担保人或者配偶
	* @author zhangpp
	* @Title: CreditApplyAdd 
	* 
	* @param @param model
	* @param @param creditPeopleType
	* @param @param id
	* @param @param tid
	* @param @param hid
	* @param @return    设定文件 
	* @return String    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value = "CreditApplyAdd", method = RequestMethod.GET)
	public String CreditApplyAdd(Model model,String creditPeopleType,String id,String tid,String hid) {
	 	
		//判断条件
	 	viewScopeControllerHelper.preparedAttachmentEnum(model);
		model.addAttribute("uuid", UUIDFactory.getUUID());
		model.addAttribute("uuid1", UUIDFactory.getUUID());
		model.addAttribute("uuid2", UUIDFactory.getUUID());
		model.addAttribute("uuid3", UUIDFactory.getUUID());
		model.addAttribute("uuid4", UUIDFactory.getUUID());
		model.addAttribute("uuid5", UUIDFactory.getUUID());
		
		//页面传过的值
		model.addAttribute("creditPeopleType", creditPeopleType);
		model.addAttribute("id", id);
		model.addAttribute("tid", tid);
		model.addAttribute("hid", hid);
		
		
		//修复添加担保人/配偶图片不依附记录的问题
		otherAttachmentsService.deleteInvalidAttachments(id, getCurrentUser());
		
	 	return "ywShouLi/ywShenQing/CreditApplyAdd";
	}
	 
    /**
    * 业务受理  业务申请  征信信息修改
    * @author zhangpp
    * @Title: zxQueryCreditApplyUpdate 
    * 
    * @param @param model
    * @param @return    设定文件 
    * @return String    返回类型 
    * @version V1.0
    * @throws
     */
    @RequestMapping(value = "zxQueryCreditApplyUpdate", method = RequestMethod.GET)
    public String zxQueryCreditApplyUpdate(Model model,String id,String tid,String hid,String creditPeopleType) 
    {
    	ZxQueryCreditApplySub zxQueryCreditApplySub = new ZxQueryCreditApplySub();
		zxQueryCreditApplySub.setDpStatus(DpStatus.NORMAL.getCode());
		zxQueryCreditApplySub.setCreditPeopleType(CreditPeopleType.ZHU_JIE_REN.getCode());
		zxQueryCreditApplySub.setQueryCreditApplyId(id);
		zxQueryCreditApplySub = zxQueryCreditApplySubService.selectRefined(zxQueryCreditApplySub);
		if(null != zxQueryCreditApplySub) {
			model.addAttribute("uuid0", zxQueryCreditApplySub.getId());
		}
    	
		//判断条件
    	viewScopeControllerHelper.preparedAttachmentEnum(model);
		model.addAttribute("uuid", id);
		model.addAttribute("tid", tid);
		model.addAttribute("hid", hid);
		model.addAttribute("creditPeopleType",creditPeopleType);
		
		model.addAttribute("uuid1", tid);
		model.addAttribute("uuid2", tid);
		model.addAttribute("uuid3", tid);
		model.addAttribute("uuid4", tid);
		model.addAttribute("uuid5", tid);
		
    	return "ywShouLi/ywShenQing/zxQueryCreditApplyUpdate";
    }
	    
	/**
	* 业务受理  业务申请  征信查询反馈  跳转
	* @author zhangpp
	* @Title: zxQueryCreditSearchlayer 
	* 
	* @param @param model
	* @param @param id
	* @param @param tid
	* @param @param hid
	* @param @param creditPeopleType
	* @param @return    设定文件 
	* @return String    返回类型 
	* @version V1.0
	* @throws
	 */
	@RequestMapping(value = "zxQueryCreditSearchlayer", method = RequestMethod.GET)
    public String zxQueryCreditSearchlayer(Model model,String id,String tid,String hid,String creditPeopleType,String zxcxApplyId)
	{
		//判断条件
   	    viewScopeControllerHelper.preparedAttachmentEnum(model);
		model.addAttribute("uuid", id);
		model.addAttribute("tid", tid);
		model.addAttribute("hid", hid);
		model.addAttribute("zxcxApplyId", zxcxApplyId);
		model.addAttribute("creditPeopleType",creditPeopleType);
		
		String sqlXmls = "select count(t.id) count from zx_credit_query t where t.id = '"+hid+"' and t.operator_id is not null and t.dp_status = 1";
		int count = publicService.countSqlXmls(sqlXmls);
		if(count < 1)
		{
			AbstractSysUser currentUser = getCurrentUser();
    		String operatorId = currentUser.getId();
    		String operatorName = currentUser.getName();
    		
			ZxCreditQuery zxCreditQuery = new ZxCreditQuery();
			zxCreditQuery.setId(hid);
			zxCreditQuery.setOperatorId(operatorId);
			zxCreditQuery.setOperatorName(operatorName);
			count = zxCreditQueryMapper.updateByPrimaryKeySelective(zxCreditQuery);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"zxCreditQueryMapper error");
			}
		}
		
		OtherAttachments otherAttachments = new OtherAttachments();
		otherAttachments.setDataid(id);
		otherAttachments.setModeId(ModeIDType.ZXCX.getCode());
		otherAttachments.setSubDataid(tid);
		otherAttachments.setAttachmentType(AttachmentType.WORD.getCode());
		otherAttachments.setDpStatus(DpStatus.NORMAL.getCode());
		otherAttachments = otherAttachmentsService.selectRefined(otherAttachments);
		if(null != otherAttachments)
		{
			model.addAttribute("ossPath", iQiniuFileService.getURL(otherAttachments.getOssPath()));
		}
    	return "ywShouLi/ywShenQing/zxQueryCreditSearchlayer";
    }
}
